/**
 * TypeHierarchyPane.java
 * @author: liuex
 * 2008-1-17 ����01:47:14
 *
 * note: 
 */
package org.lex.reflect.browsing.view.browser;

import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

import org.lex.swing.ContainerFactory;


public class TypeHierarchyPane extends JPanel {
	private JSplitPane splitPane = null;
	private InheritancePane inherit = null;
	private MethodsPane method = null;

	public TypeHierarchyPane() {
		super(new BorderLayout());
		this.initialize();
	}

	private void initialize() {
		this.method = new MethodsPane();
		this.inherit = new InheritancePane();
		this.inherit.getInheritanceTree().addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				TreePath tp = inherit.getInheritanceTree().getPathForLocation(e.getX(), e.getY());
				if (null == tp)
					return;
				Object last = tp.getLastPathComponent();
				if (null == last)
					return;
				Object value = ((DefaultMutableTreeNode) last).getUserObject();
				if (false == value instanceof Class)
					return;
				method.setClass((Class<?>) value);
			}
		});
		this.add(this.getSplitPane(), BorderLayout.CENTER);
	}

	public void setClass(Class<?> clazz) {
		this.inherit.setClass(clazz);
		this.method.setClass(clazz);
	}

	private JSplitPane getSplitPane() {
		if (null == splitPane) {
			splitPane = ContainerFactory.createBorderlessSplitPane(5);
			splitPane.setName(this.getClass().getName() + ".splitPane");
			splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
			splitPane.setLeftComponent(this.inherit);
			splitPane.setRightComponent(this.method);
			splitPane.setResizeWeight(0.55D);
		}
		return splitPane;
	}
}
